//
//  PasswordProtectWindow.m
//  ProjectTest
//
//  Created by User on 2017/10/9.
//  Copyright © 2017年 User. All rights reserved.
//

#import "PasswordProtectWindow.h"

@interface PasswordProtectWindow ()

@property (nonatomic, strong) UITextField *pwdTextField;

@end

@implementation PasswordProtectWindow

+ (PasswordProtectWindow *)sharedInstance
{
    static PasswordProtectWindow *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[PasswordProtectWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    });
    return sharedInstance;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor whiteColor];
        UITextField *textField = [[UITextField alloc] init];
        textField.frame = CGRectMake(100, 100, 200, 44);
//        textField.center = self.center;
        textField.placeholder = @"请输入密码";
        _pwdTextField = textField;
        [self addSubview:_pwdTextField];
        
        UIButton *dismissBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [dismissBtn setTitle:@"确定" forState:UIControlStateNormal];
        [dismissBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [dismissBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
        dismissBtn.frame = CGRectMake(100, 170, 60, 44);
//        dismissBtn.center = CGPointMake(self.center.x, self.center.y + 60);
        [self addSubview:dismissBtn];
    }
    return self;
}

- (void)show:(UIViewController *)viewController
{
    self.rootViewController = viewController;
    self.windowLevel = UIWindowLevelAlert;
    [self makeKeyAndVisible];
    self.hidden = NO;
}

- (void)dismiss
{
    [_pwdTextField resignFirstResponder];
    [self resignKeyWindow];
    self.hidden = YES;
}

@end
